package com.compass.doctor.ui.prescription.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.doctor.R
import com.compass.doctor.databinding.LayoutScreenItemBinding
import com.compass.doctor.databinding.LayoutSetDataItemBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseMultiItemAdapter
import com.compass.framework.ext.saveAs
import com.compass.framework.model.ScreenTag
import com.compass.framework.utils.getColorFromResource
import com.compass.framework.utils.getDrawableResource

/**
 * Description： 筛选adapter
 * Date:2023/12/19 11:27
 */
class ScreenAdapter constructor(private var itemType: Int) : BaseMultiItemAdapter<ScreenTag>() {


    //用来实现多item布局
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }

    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: ScreenTag?,
        position: Int
    ) {
        if (item == null) return
        //  //1、普通的，  else其他的
        when (holder.itemViewType) {
            1 -> {
                val binding = holder.binding.saveAs<LayoutScreenItemBinding>()
                binding.tvScreenName.text = item.name
                if (item.isSelect){
                    binding.tvScreenName.background= getDrawableResource(R.drawable.btn_shape_screen_selected)
                    binding.tvScreenName.setTextColor(getColorFromResource(R.color.white))
                }else{
                    binding.tvScreenName.setTextColor(getColorFromResource(R.color.color_2e344a))
                    binding.tvScreenName.background= getDrawableResource(R.drawable.bg_shape_round_f8_3)
                }
            }
            else -> {
                val binding = holder.binding.saveAs<LayoutSetDataItemBinding>()
                binding.tvScreenName.text = item.name
                if (item.isSelect){
                    binding.tvScreenName.background= getDrawableResource(R.drawable.btn_shape_screen_selected)
                    binding.tvScreenName.setTextColor(getColorFromResource(R.color.white))
                }else{
                    binding.tvScreenName.background= getDrawableResource(R.drawable.bg_shape_round_f8_3)
                    binding.tvScreenName.setTextColor(getColorFromResource(R.color.color_2e344a))
                }
            }


        }


    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {
            1 -> {
                LayoutScreenItemBinding.inflate(layoutInflater, parent, false)
            }

            else -> {
                LayoutSetDataItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }

}